<?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * M_verificationlink
 *
 * This is an M_resendverificationlink of a few basic verificationlink interaction methods you could use
 * all done with a hardcoded array.
 *
 * @package		CodeIgniter
 * @subpackage	Rest Server
 * @category	Controller
 * @author		Phil Sturgeon
 
*/

// This can be removed if you use __autoload() in config.php OR use Modular Extensions
require APPPATH.'/libraries/REST_Controller.php';

class Mrequestqr extends REST_Controller
{
	function __construct()
	{
		parent::__construct();
		$this->load->model('mdl_mrequestqr');
		
	}

   /* function verificationlink_post()
    {
        //$this->some_model->updateverificationlink( $this->get('id') );
     
		
$data['username']=$this->post('username'); 
$data['password']=$this->post('password'); 
$data['level_id']=$this->post('level_id'); 



		$query = $this->mdl_verificationlink->insert($data);
		
	
		if ($query){
			
			$this->response(array('status' => 'true'),200);
		}else{
			$this->response(array('status' => 'false'));
		}

    }
	*/
	
	function check_mrequestqr_post(){
		      
$data = array();
		//post
		$this->load->helper('jwt_helper');
		$data['mappsidonapps']=$this->post('mappsidonapps'); 
		$data['musername']=$this->post('username'); 
		$data['channelid']=$this->post('channelid'); 
		$data['serviceid']=$this->post('serviceid'); 
		$data['amount']=$this->post('amount'); 
		$token = JWT::decode($_POST['token'], 'dompeto');
		
		$mappsidonappstoken= $token->mappsidonapps;
        $usernametoken= $token->username;
        	
		$this->load->helper('date');
$timeid = "%Y%m%d%h%i%s";
$time = time();
$ts=mdate($timeid, $time);
$refid = random_string('numeric', 4);		
$referenceid = $ts.$refid;		
$data['referenceid']=$referenceid; 			

$datestring = "%Y-%m-%d %h:%i:%s";
$time = time();
$opentrxdate=mdate($datestring, $time);

$data['opentrxdate']=$opentrxdate; 
		if($data['mappsidonapps']==$mappsidonappstoken && $data['musername']==$usernametoken) {
		
		// --- start create reference id
		
		//$arrwhere="channelid = '" . $channelid  . "'";
		$query = $this->mdl_mrequestqr->insert($data);
		
		$arrwhere="channelid = '" . $data['channelid'] . "'";
		$query2 = $this->mdl_mrequestqr->get_channeltitle(0, 0, $arrwhere);
		$result2 = $query2->result_array();
		$channeltitle = $result2[0]['channeltitle'];
	
		$arrwhere="serviceid = '" . $data['serviceid'] . "'";
		$query3 = $this->mdl_mrequestqr->get_servicetitle(0, 0, $arrwhere);
		$result3 = $query3->result_array();
		$servicetitle = $result3[0]['servicetitle'];
			
			$requestqr[] = array(
				'mappsidonapps' => $mappsidonappstoken ,
				'referenceid' => $referenceid, 
				 'channelid' => $data['channelid'],
				 'channeltitle' => $channeltitle,
				 'serviceid' => $data['serviceid'],
				  'servicetitle' => $servicetitle,
				  'operator' => $data['musername'], 
				     'amount' => $data['amount'],
				'requeststatus' => 'true',
				'qrcodeinformation' => array(
				'ReferenceID'=>$referenceid,
				'Amount'=>$data['amount'],
				'Poin'=>'',
				'MerchantID'=>$data['channelid'],
				'TerminalID'=>$data['mappsidonapps'],                                        
				'Operator'=>$data['musername'],
				'Dapat Poin'=>''
				),
				'description'=>'sukses',
				'debug' => 'generate qrcode'
				);
		} else {
				
	
			$requestqr[] = array(
				'mappsidonapps' => $mappsidonappstoken ,
				'referenceid' => 'false', 
				 'channelid' => 'false',
				  'serviceid' => 'false',
				   'operator' => 'false', 
				     'amount' => 'false',
				'requeststatus' => 'false',
				'description'=>'false',
				'debug' => 'username salah'
				);
		}
		
	
	
		
		
	 $this->response($requestqr, 200);	
			
	
	}
    /*
    function verificationlink_delete()
    {
		
    	//$this->some_model->deletesomething( $this->get('id') );$this->_get('id')
        $message = array('message' => 'DELETED!', 'id'=>$this->delete('id'));
		
		$query = $this->mdl_verificationlink->delete($this->delete('id'));
		//$this->response($message,200);
		//$query=1;
		if ($query){
			$this->response(array('status' => 1),200);
		
		}else{
			$this->response(array('status' => 0));
		}
      
    } */
	/*
	 function verificationlink_put()
    {
		
    	//$this->some_model->deletesomething( $this->get('id') );$this->_get('id')
        //$message = array('message' => 'UPDATE!', 'userid'=>$this->delete('userid'), 'name'=>$this->delete('name'));
		$data['userid']=$this->put('userid'); 
$data['username']=$this->put('username'); 
$data['password']=$this->put('password'); 
$data['level_id']=$this->put('level_id'); 

		$query = $this->mdl_verificationlink->update($data['userid'],$data);
		//$this->response($message,200);
		
		if ($query){
			$this->response(array('status' => 1),200);
		
		}else{
			$this->response(array('status' => 0));
		}
      
    } */
    /*
    function verificationlinks_get()
    {
        //$verificationlinks = $this->some_model->getSomething( $this->get('limit') );
        $verificationlinks = array(
			array('id' => 1, 'name' => 'Some Guy', 'email' => 'example1@example.com'),
			array('id' => 2, 'name' => 'Person Face', 'email' => 'example2@example.com'),
			3 => array('id' => 3, 'name' => 'Scotty', 'email' => 'example3@example.com', 'fact' => array('hobbies' => array('fartings', 'bikes'))),
		);
        
        if($verificationlinks)
        {
            $this->response($verificationlinks, 200); // 200 being the HTTP response code
        }

        else
        {
            $this->response(array('error' => 'Couldn\'t find any items!'), 404);
        }
    } */
/*

	public function send_post()
	{
		var_dump($this->request->body);
	}
*/
/*
	public function send_put()
	{
		var_dump($this->put('foo'));
	}
	*/
}